<template>
    <div class="search-container">
        <div class="top">
            <input class="city-input" type="text" placeholder="请输入" @change="valueChange" ref="city">
            <mt-button type="primary" plain @click="acquireInfo">天气查询</mt-button>
        </div>
        <div class="bottom-content">
            <div class="wrap-content" v-for="item in channellist" :key="item.channelid">
                <div class="small-content" @click="clickEvent(item.name)">
                    <img :src="item.thumb"/>
                    <h4>{{item.name}}</h4>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui'
    export default {
        data () {
            return {
                city:'',
                channellist:[]
            }
        },
        mounted () {
            this.acquireInfo();
        },
        methods: {
            valueChange () {
                this.city = this.$refs.city.value
            },
            acquireInfo () {
                console.log(this.city)
                if (this.city.length > 0) {
                    this.$http.get('https://api.apiopen.top/musicBroadcasting')
                        .then(response=>{
                            let obj = response.body
                            if (obj.code == 200) {
                                this.channellist = obj.result[0].channellist
                            }
                        }, (error)=>{
                            console.log('请求音乐电台接口失败')
                        })
                }
                this.$refs.city.value = ''
                this.city = ''
            },
            clickEvent(msg) {
                Toast(msg)
            }
        }
    }
</script>

<style scoped lang="scss">
    .search-container {
        .top {
            display: flex;
            justify-content: center;
            .city-input {
                border: 1px solid red;
                border-radius: 5px;
                padding-left: 10px;
            }
            .mint-button {
                margin-left: 10px;
            }
        }
        .bottom-content {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            align-items: center;
            .wrap-content {
                width: 50%;
                .small-content {
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    padding-top: 10px;
                    img {
                        width: 150px;
                        height: 150px;
                        border: 0;
                        vertical-align: bottom;
                        border-radius: 15px;
                    }
                    h4 {
                        margin: 0;
                        padding: 0;
                        text-align: center;
                    }
                }
            }
        }
    }
</style>
